<?php

class Account_info  extends AdminManage
{
    
     public $per_page=30;
      public $np;
      public $begin;
    
	/**
	 * 初始化
	 */
	public function _init()
	{
        #权限 lee
        $this->checkAuthority(); 
        $this->np = (int)$_GET['p']>0 ? (int)$_GET['p']:1;  //当前页,默认为1
        $this->begin = ($this->np-1) * $this->per_page;  //从第几条记录返回
	}

	/**
	 * 默认动作
	 */
	protected function _default()
	{
		
		$this->assign('menu_navbar','账户管理  -- <a href="'.$_GET['action'].'.html">账号信息</a>');
        
		$where = ' 1 ';
		
		 #查询条件处理-start
		 $joinTimeStart = $this->getParam('jts');
         $joinTimeend   = $this->getParam('jte');
		 $state   = $this->getParam('state');
		 $depart   = $this->getParam('depart');
		 $keyword   = $this->getParam('kw');
		#查询条件处理-end
		
		$datelinesStamp = strtotime($joinTimeStart);
		$datelinedStamp = strtotime($joinTimeend." 23:59:59");
			
		if($datelinesStamp) {
			$where .= ' and joinTime >= ' . $datelinesStamp;
			$this->assign('jts',$joinTimeStart);
		}
		if($datelinedStamp) {
			$where .= ' and joinTime <= ' . $datelinedStamp;
			$this->assign('jte',$joinTimeend);
		}
		
		
		if(is_numeric($state) && in_array($state,array(0,1))){
			$where .= ' and state  = ' . $state;
			$this->assign('state',$state==1?'pass':'nopass');
		}
		
		
		if(is_numeric($depart)){
			$where .= ' and group_id  = ' . $depart;
			$this->assign('depart',$depart);
		}
		
		if(!empty($keyword)){
		    $kwlen = strlen($keyword);
			if(is_numeric($keyword) && in_array($kwlen,array(11,12,13))){
				$where .= " and mobile  like '%" . $keyword."%'";
			}else{
				$where .= " and fullName  like '%" . $keyword."%'";
			}
			$this->assign('kw',$keyword);
		}
				
		if($where){
			$where = ' where '.$where;
		}
		
         $sql = "select id,username, fullName as name,state,dateline,firstTime,joinTime,tel,qq,email,logo,mobile,sex,group_id from system  ".$where." order by id DESC";
    	$mysqlData = DB::select($sql,$this->per_page,$this->begin);//查询记录 
		
        $sql = "select count(1) CNT from system where state=1";
    	$totalRows = DB::select($sql,-1);//总记录数
    	$dpage = new Dpage($totalRows,$this->per_page,$this->np);	//分页显示
    	$pageform = $dpage->outputPages();
		
		#数据二次处理
		if($mysqlData){
			foreach ($mysqlData as $k=>$v){
				#状态
				if($v['STATE']==1){
					$mysqlData[$k]['STATENAME'] = '<span class="status-normal">正常</span>';
				}else{
					$mysqlData[$k]['STATENAME'] = '<span class="status-cancel">注销</span>';
				}
				#获取所属部门
				if($v['GROUP_ID']){
					$arrDepart = $this->get_department_info($v['GROUP_ID']);
					if($arrDepart){
						$mysqlData[$k]['GROUPNAME'] = $arrDepart[0]['GROUPNAME'];
					}
				}
			}//end foreach
		}
		
		
		#获取到部门信息
		$arrDepartment = $this->get_department_info();
		$this->assign('arrDepartment',$arrDepartment);
		
        $this->assign('list',$mysqlData);
        $this->assign('pageform',$pageform);
		$this->tpl_full_path('/admins/account/index');
	}
	
	
	/**
	 * 状态操作
	 */
	protected function _dostate()
	{
		$id = $this->getParam('id');
		$type = $this->getParam('type');
		if(empty($id) && empty($type)){
			die('0');
		}
		$arrUpdate = array();
		if($type == 'pass'){
			$arrUpdate['state'] = 1;
		}else{
		    $arrUpdate['state'] = 0;
		}
		$arrUpdate['dateline'] = time();
		$updateStatus = DB::update('system','id = '.$id,$arrUpdate);
		if($updateStatus){
		   die('1');	
		}else{
		   die('0');
		}
		
	}



}
?>
